package com.tjn.list_;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class LinkedListARSG {
    @SuppressWarnings("all")
    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList();

        //看这些方法的源码
        //添加结点
        linkedList.add("1");
        linkedList.add("2");
        linkedList.add("3");
        System.out.println(linkedList);

        //删除结点
        linkedList.remove();//默认删除第一个结点
        //linkedList.remove("1");//删除指定结点
        System.out.println(linkedList);

        //修改结点
        linkedList.set(0, "100");
        System.out.println(linkedList);

        //获取结点
        System.out.println(linkedList.get(0));

        //遍历方式有三种，增强for，迭代器，普通for
        //增强for
        System.out.println("===增强for===");
        for (Object o : linkedList) {
            System.out.println(o);
        }

        //迭代器
        System.out.println("===迭代器===");
        Iterator iterator = linkedList.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }

        //普通for
        System.out.println("===普通for===");
        for (int i = 0; i < linkedList.size(); i++) {
            System.out.println(linkedList.get(i));
        }
    }

}
